package com.pjmike.netty.protocol.message.encoder;

import com.pjmike.netty.protocol.message.command.Command;
import com.pjmike.netty.protocol.message.packet.response.TrafficDataResponsePacket;
import com.pjmike.netty.utils.DataTransformUtil;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

import java.util.zip.CRC32;

/**
 * @Author bj
 * @Description //路口交通参数记录上传返回报文加密
 * @Date 19:09 2021/1/10
 * @Param
 * @return
 **/
public class TrafficDataEncoder extends MessageToByteEncoder<TrafficDataResponsePacket> {
    @Override
    protected void encode(ChannelHandlerContext ctx, TrafficDataResponsePacket msg, ByteBuf out) throws Exception {
        //报文头
        short bt = msg.getBt();
        out.writeByte((byte) bt);
        //协议号
        out.writeShort(Command.TRAFFIC_DATA_RESPONSE);
        //设备编号
        out.writeBytes(msg.getSbbh().getBytes());
        //数据长度
        out.writeInt(36);
        //统计编号
        out.writeBytes(msg.getTjid().getBytes());
    }
}
